package com.summer.bilibili.exception;


import com.summer.bilibili.consts.Code;
import com.summer.bilibili.util.R;
import lombok.Data;
import lombok.EqualsAndHashCode;


/**
 * @classname CustomException
 * @description 自定义运行时异常类
 * @author: summer
 */
@EqualsAndHashCode(callSuper = true) // 生成equals和hashCode方法时包含父类的字段
@Data
public class CustomException extends RuntimeException {
    private final R < ? > result;

    public CustomException () {
        this ( Code.ERROR );
    }

    public CustomException ( String message ) {
        this ( Code.ERROR , message );
    }

    public CustomException ( R < ? > result ) {
        super ( result.getMsg ( ) );
        this.result = result;
    }

    public CustomException ( Code code ) {
        this ( code , code.getMsg ( ) );
    }

    public CustomException ( Code code , String message ) {
        super ( message );
        this.result = new R <> ( code.getValue ( ) , message , null );
    }
}
